<style type="text/css">
	#J_calculate_form .f-input,.f-select-s{ border:1px solid #ccc; background:#fff; height:28px;padding:5px 10px; width:120px; border-radius: 5px!important; font-size:14px; font-weight:bolder;color:#666}
	#J_calculate_form .f-select-s h3{ font-size:14px; display:block; height:28px; line-height:28px; overflow:hidden;}
	#J_calculate_form .f-select-s .dropdown{  left:-1px; padding-top:0px; border:1px solid #ddd; background:#fff; width:150px; top:38px}
	#J_calculate_form .f-select-s .dropdown a{ display:block; background:#fff; padding:0 8px; height:32px; line-height:32px; font-weight:normal;}
	#J_calculate_form .f-select-s .dropdown a:hover{ background:#f1f1f1}
	#J_calculate_form .sub_btn{color: #fff;background-color: #0697da; border:none;border-radius: 5px!important;height: 40px!important;width: 165px!important;line-height: 40px;}
</style>
<div class="list" style="overflow:visible;">
	<div class="list_title clearfix">
		<div class="cur">借款设置</div>
	</div>
	<div class="p10 cf" style="border-top:0">
		
		<div class="blank10"></div>
		<div class="cf pt5 pb5 pl5 pr5">
			<form action="{$APP_ROOT}" method="post" name="J_calculate_form" id="J_calculate_form">
			<div class="p5" style="width:800px;line-height:40px">
	            <div class="clearfix">
	                <div class="f_l" style="width:400px">
	                	<span class="f_l">借款金额：</span><input type="text" id="borrowAmount" name="borrowamount" class="f-input f_l mr5">元
	                </div>
	                <div class="f_l" style="width:400px">
	                	 <span class="f_l">年&nbsp;&nbsp;利&nbsp;&nbsp;率：</span><input type="text" id="apr" name="apr" class="f-input f_l mr5">%
	                </div>
					<div class="blank20"></div>
	                 <div class="f_l" style="width:220px">
	                	 <span class="f_l"> 借款期限：</span><input type="text" id="repayTime" name="repaytime" class="f-input f_l mr5">
	                </div>
					<div class="f_l f-select-box" style="width:180px">
	                	<div class="f-select-s f_l pr" style="width:60px">
	                		<h3></h3>
							<div class="dropdown hide ps"  style="width:80px"></div>
	                	</div>
						<select class="hide" name="repaytimetype" id="repaytimetype">
							<option value="1">月</option>
	                        <option value="0">天</option>
	                    </select>
	                </div>
	                <div class="f_l f-select-box" style="width:400px">
	                	<span class="f_l">还款方式：</span><div class="f-select-s f_l pr">
	                		<h3></h3>
							<div class="dropdown hide ps"></div>
	                	</div>
						<select class="hide" name="borrowpay" id="borrowpay">
							{foreach from="$loantype_list" item="loantype"}
	                        <option value="{$loantype.key}" rel="{$loantype.repay_time_type_str}">{$loantype.name}</option>
							{/foreach}
	                    </select>
	                </div>
					<div class="blank20"></div>
					<div class="f_l f-select-box" style="width:400px">
	                	<span class="f_l">等&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;级：</span><div class="f-select-s f_l pr">
	                		<h3></h3>
							<div class="dropdown hide ps"></div>
	                	</div>
						<select class="hide" name="level" id="level">
							{foreach from="$level_list" item="level"}
	                        <option value="{$level.id}">{$level.name}</option>
							{/foreach}
	                    </select>
	                </div>
					 <div class="f_l" style="width:400px">
	                	 <span class="f_l"> 逾期天数：</span><input type="text" value="0" id="impose_day" name="impose_day" class="f-input f_l mr5">天/每期
	                </div>
	            </div>
				<div class="blank10"></div>
	            <div class="clearfix">
	                <div class="" style="margin:0;width:400px">
	                    <label><input type="checkbox" name="isshow" value="1" checked="checked" id="isShow">&nbsp;&nbsp;显示还款时间表</label>&nbsp;&nbsp;&nbsp;
	               		<label id="J_inrepayshow"><input type="checkbox" name="inrepayshow" value="1" checked="checked" id="isShow">&nbsp;&nbsp;显示提前还款罚息表</label>
				    </div>
	                <div style="padding:10px 0 0 0">
	                    <button class="sub_btn" id="J_saveSettingBnt" type="button">
	                    	开始计算
	                    </button>
						<span style="color: red" id="T_error"></span>
	                </div>
	            </div>
	        </div>
			</form>
		</div>
		<div class="blank20"></div>
		
	</div>
</div>

<div id="J_calculate_Result"></div>

<script type="text/javascript">
	
	jQuery(function(){
		$(".f-select-box select").each(function(){
			var h = 1;
			$(this).find("option").each(function(){
				var obj = $(this);
				var box = $(this).parent().parent();
				if (h == 1) {
					box.find("h3").html(obj.html());
				}
				
				box.find(".dropdown").append("<div rel='"+obj.attr("value")+"'><a href='javascript:void(0);'>"+obj.html()+"</a></div>");
				h++;
			});
			
		});
		
		
		$(".f-select-box h3").click(function(){
			$(".dropdown").addClass("hide");
			var obj = $(this);
			var box = $(this).parent();
			box.find(".dropdown").removeClass("hide");
			$("body").one("click",function(){
				box.find(".dropdown").addClass("hide");
			});
			return false;
		});
		$(".f-select-box .dropdown a").click(function(){
			var obj = $(this);
			var box = $(this).parent().parent().parent().parent();
			box.find("h3").html($(this).html());
			var v = obj.parent().attr("rel");
			box.find("select").val(parseInt(v)).trigger("change");
			box.find(".dropdown").addClass("hide");
		});
		
		$("#repaytimetype").change(function(){
			var seleted = -1;
			var p_rel = $(this).val();
			var select_rel = $("#borrowpay option[value='"+$("#borrowpay").val()+"']").attr("rel");
			var select_rel_str = select_rel.split(",");
			for(var i=0;i<select_rel_str.length;i++){
				if(seleted == -1 && parseInt(select_rel_str[i]) == parseInt(p_rel)){
					seleted = 0;
				}
			}
			
			if(seleted == -1){
				$("#borrowpay option").each(function(){
					var rel = $(this).attr("rel");
					var rel_str = rel.split(",");
					for(var i=0;i<rel_str.length;i++){
						if(seleted == -1 && parseInt(rel_str[i]) == parseInt(p_rel)){
							$("#borrowpay").val($(this).val());
							$("#borrowpay").parent().find(".f-select-s h3").html($(this).html());
							seleted = parseInt(rel_str[i]);
						}
					}
				});
			}
			
			if($(this).val()==0){
				$("#J_inrepayshow").hide();
			}
			else{
				$("#J_inrepayshow").show();
			}
		});
		
		$("#borrowpay").change(function(){
			var val = $(this).val();
			var rel = $(this).find("option[value='"+val+"']").attr("rel");
			var rel_str = rel.split(",");
			var has_day = 0;
			for(var i=0;i<rel_str.length;i++){
				if(has_day==0 && parseInt(rel_str[i]) == 0){
					has_day = 1;
				}
			}
			
			if(has_day==0){
				$("#repaytimetype").val(1);
				$("#repaytimetype").parent().find(".f-select-s h3").html("月");
			}
			if($("#repaytimetype").val()==0){
				$("#J_inrepayshow").hide();
			}
			else{
				$("#J_inrepayshow").show();
			}
		});
		
		$("#J_saveSettingBnt").click(function(){
			$("#borrowpay-box .dropdown").addClass("hide");
			$("#T_error").html("");
			if($.trim($("#borrowAmount").val())=="" || $("#borrowAmount").val()%1 !=0){
				$("#T_error").html("借款金额必须为正整数!");
				return false;
			}
			if($.trim($("#apr").val())=="" || isNaN($.trim($("#apr").val()))){
				$("#T_error").html("年利率必须为数字类型!");
				return false;
			}
			if($.trim($("#repayTime").val())=="" || isNaN($.trim($("#repayTime").val()))){
				$("#T_error").html("月份格必须为数字类型!");
				return false;
			}
			if($.trim($("#repayTime").val())>120){
				$("#T_error").html("月份必须在120以内!");
				return false;
			}
			var query = $("#J_calculate_form").serialize();
			$.ajax({
				url:APP_ROOT + "/index.php?ctl=tool&act=ajax_calculate",
				data:query,
				type:"post",
				success:function(result){
					$("#J_calculate_Result").html(result);
					return false;
				}
			});
			return false;
		});
	});

</script>
